//
//  MagnifierView.swift
//  elarc01
//
//  Created by elarc on 16/6/24.
//  Copyright © 2016年 elarc. All rights reserved.
//

import UIKit

class Magnifier: UIWindow {
    
    var touchPoint:CGPoint?{
        didSet{
            self.center = CGPointMake(touchPoint!.x, touchPoint!.y-10)
        }
    }
    var viewToMagnify = UIView()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.frame = CGRectMake(0, 0, 80, 80)
        self.layer.borderColor = UIColor.lightGrayColor().CGColor
        self.layer.borderWidth = 3
        self.layer.cornerRadius = 40
        self.layer.masksToBounds = true
        self.window?.windowLevel = UIWindowLevelAlert
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func drawRect(rect: CGRect) {
        let context = UIGraphicsGetCurrentContext()
        CGContextTranslateCTM(context,1*(self.frame.size.width*0.5),1*(self.frame.size.height*0.5));
        CGContextScaleCTM(context, 1.5, 1.5);
        CGContextTranslateCTM(context,-1*(touchPoint!.x),-1*(touchPoint!.y));
        self.viewToMagnify.layer.renderInContext(context!)
    }
    
}
